package com.manage.platform.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manage.platform.dto.TaskAchieveFileLinkDto;
import com.manage.platform.entity.TaskAchieveFileEntity;
import com.manage.platform.entity.TaskAchieveFileLinkEntity;
import com.manage.platform.mapper.TaskAchieveFileLinkMapper;
import com.manage.platform.mapper.TaskAchieveFileMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * YWD
 * 2025/11/24
 */
@AllArgsConstructor
@Service
public class TaskAchieveFileLinkServiceImpl extends ServiceImpl<TaskAchieveFileLinkMapper, TaskAchieveFileLinkEntity> {


    public Boolean saveTaskAchieve(Long taskAchieveFileId, List<TaskAchieveFileLinkDto> achieveFileLinkVoList) {
        achieveFileLinkVoList.forEach(item -> {
            item.setTaskAchieveFileId(taskAchieveFileId);
        });
        return saveBatch(BeanUtil.copyToList(achieveFileLinkVoList, TaskAchieveFileLinkEntity.class));
    }


    public Boolean updateTaskAchieve(Long taskAchieveFileId, List<TaskAchieveFileLinkDto> achieveFileLinkVoList) {
        achieveFileLinkVoList.forEach(item -> {
            item.setTaskAchieveFileId(taskAchieveFileId);
        });
        return saveBatch(BeanUtil.copyToList(achieveFileLinkVoList, TaskAchieveFileLinkEntity.class));
    }


    public Boolean removeByTaskAchieveFileId(Long taskAchieveFileId) {
        LambdaQueryWrapper<TaskAchieveFileLinkEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskAchieveFileLinkEntity::getTaskAchieveFileId, taskAchieveFileId);
        return this.remove(queryWrapper);
    }

    public Boolean deleteTaskAchieve(List<Long> taskAchieveFileIds) {
        LambdaQueryWrapper<TaskAchieveFileLinkEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(TaskAchieveFileLinkEntity::getTaskAchieveFileId, taskAchieveFileIds);
        return this.remove(queryWrapper);
    }
}
